﻿using Architecture.Domain.TestModel.Samples;
using Architecture.Services.ServicesInterfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.ServiceModel;
using System.Web;
using System.Web.Http;

namespace Architecture.Presentation.WebApiServices2.Controllers
{


    public class AppContext
    {
        private const string APP_CONTEXT = "AppContext";
        // TODO: Update this with as many fields as needed 
        public string Data { get; private set; }

        public AppContext(string Data)
        {
            this.Data = Data;
        }
        public static AppContext Current
        {
            get { return (AppContext)HttpContext.Current.Items[APP_CONTEXT]; }
            set { HttpContext.Current.Items[APP_CONTEXT] = value; }
        }
    }


    public class OrganisationController : ApiController
    {
        // GET: api/Organisation
        public IEnumerable<Organisation> Get()
        {
            //ChannelFactory<IOrganisationService> factory = new ChannelFactory<IOrganisationService>("IOrganisationServiceClient");
            //IOrganisationService svc = factory.CreateChannel();


            //((IClientChannel)svc).Closed += (s, e) =>
            //{
            //    factory.Close();
            //};
            //try
            //{
            //    return svc.GetOrganisations().ToList();
            //}
            //catch
            //{
            //    ((IClientChannel)svc).Abort();
            //    throw;
            //}
            //finally
            //{
            //    ((IClientChannel)svc).Close();
            //    ((IClientChannel)svc).Dispose();
            //}

            //return new List<Organisation>();
            return new OrganisationRepository().GetOrganisations();
        }

        // GET: api/Organisation/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/Organisation
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/Organisation/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/Organisation/5
        public void Delete(int id)
        {
        }
    }
}
